--- title: The peak pattern puzzle keywords: fastai sidebar: home_sidebar summary: "Matching peak patterns " description: "Matching peak patterns " nb_path: "notebooks/40_peak-pattern-puzzle.ipynb" ---
In the previous steps we have computed the hotmax spectra and within each spectrum detected peaks above the Poison noise level. All this preliminary work was needed to arrive at the central problem of MA-XRF analysis: solving the peak pattern puzzle. For each individual hotmax spectrum I would like to explain the presence of all peaks above the Poison noise level.
Before trying to assign peaks to the presence of specific elements in the scanned object, one should identify instrumental peaks that result from the physics of the instrument sensor or Rhodium anode.
from maxrf4u import HotmaxAtlas
hma = HotmaxAtlas('RP-T-1898-A-3689.datastack')
hma.plot_spectra()
Or we can plot a single spectrum with HotmaxAtlas.plot_spectrum(<nr>)) to inspect a specific hotmax spectrum.
hma.plot_spectrum(4, headspace=3);
Now we can start to 'explain away' all peaks...
To be continued...
hma = HotmaxAtlas('RP-T-1898-A-3689.datastack')
fig, ax = plt.subplots(figsize=[9, 9])
n = 4
ann_list = hma.plot_spectrum(n, ax=ax, headspace=2)
eoi_ptrns = get_patterns(eoi)
twax = ax.twinx()
plot_patterns(eoi_ptrns, ax=twax)
len(eoi)
get_patterns(['Fe'])
ptrn_list = get_patterns(eoi)
Let's plot these patterns
ptrn_list = get_patterns(eoi)
plot_patterns(ptrn_list)
ptrn_list
def get_instrument_patterns(datastack_file, anode='Rh', prominence=0.35):
'''Create instrument peak pattern dictionaries for sensor peak and Compton and elastic anode peaks.'''
ds = maxrf4u.DataStack(datastack_file)
# read max spectrum
ds = maxrf4u.DataStack(datastack_file)
x_keVs = ds.read(ds.MAXRF_ENERGIES)
y_max = ds.read(ds.MAXRF_MAXSPECTRUM)
# locate peaks in max spectrum
peak_indices, _ = ssg.find_peaks(y_max, prominence=prominence)
peaks_x = x_keVs[peak_indices]
# assumes first peak is (negative) sensor peak
sensor_keV = peaks[0]
sensor_ptrn = {'source': 'SENSOR',
'peaks_xy': np.array([[sensor_keV, 1]])}
# anode peak pattern (including Compton)
rhodium_peaks_x = mos.XFluo('Rh', tube_keV=40).peak_energies
Rh
#anode_ptrn =
return peaks_x
datastack_file = 'RP-T-1898-A-3689.datastack'
ds = maxrf4u.DataStack(datastack_file)
y_sum = ds.read('maxrf_sumspectrum')
y_sum_without_sensor_peak = y_sum.copy()
y_sum_without_sensor_peak[x_keV < 1] = 0
Rh_Compton_i = np.argmax(y_sum_without_sensor_peak)
Rh_Compton_keV = x_keV[Rh_Compton_i]
Rh_Compton_keV
rhodium_spectrum = mos.XFluo('Rh', tube_keV=40)
rhodium_spectrum.peak_intensities
rhodium_spectrum.peak_energies
maxrf4u.RHODIUM_Ka
peaks_x = get_instrument_patterns('RP-T-1898-A-3689.datastack')
peaks_x
Let's plot these patterns...
eoi
First we need to add the ANODE and SENSOR patterns.
ptrn_list
Then, we need to start matching the peak patterns.